﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackSystem.IO.Formula;

namespace TrackSystem.IO.Logics
{
    /// <summary>
    /// 逻辑属性
    /// </summary>
    public class LogicItem
    {
        /// <summary>
        /// 逻辑回路名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 条件表达式
        /// </summary>
        public string condFormula { get; set; }

        /// <summary>
        /// 使能标志
        /// </summary>
        public bool Enabled { get; set; }

        /// <summary>
        /// 条件表达式中缀形式的堆栈
        /// </summary>
        public Stack<ExprItem> condStack { get; set; }

        /// <summary>
        ///  条件表达式的结果
        /// </summary>
        public OperandDef condValue { get; set; }

        /// <summary>
        /// 计算表达式
        /// </summary>
        public string clacFormula { get; set; }

        /// <summary>
        /// 计算表达式中缀形式的堆栈
        /// </summary>
        public Stack<ExprItem> clacStack { get; set; }

        /// <summary>
        /// 字符形式的表达式列表
        /// </summary>
        public List<string> lstStrFormual { get; set; }

        /// <summary>
        /// 表达式列表
        /// </summary>
        public List<FormulaItem> lstFormual { get; set; }

        /// <summary>
        /// 计算表达式的结果
        /// </summary>
        public List<OperandDef> lstValue { get; set; }

        /// <summary>
        /// 计算表达式的上次结果
        /// </summary>
        public List<OperandDef> lastlstValue { get; set; }

        /// <summary>
        ///  输出寄存器列表
        /// </summary>
        public List<string> OutRegsName { get; set; }

        /// <summary>
        /// 每次修改寄存器的值还是结果改变才修改
        /// </summary>
        public bool UpdateWenChanged { get; set; }
        
        /// <summary>
        /// 装备的ID号
        /// </summary>
        public int EquipId { get; set; }

        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="idx">属性号索引</param>
        /// <returns></returns>
        public OperandDef GetVal(int idx)
        {
            if (idx == 0)
            {
                return new OperandDef(Enabled);
            }
            else if (idx == 1) {
                return condValue;
            }
            else if (idx == 2 && lastlstValue.Count > 0) {
                return lastlstValue[0];
            }

            return new OperandDef();
        }
    }
}
